/**
 * This is a utility taglib class for tags that have a generic utility function.
 */
class AuthTagLib {

    // This calculates whether a user has a particular role assigned to them
    def authUserHasRole = { attrs ->
        def roleName = attrs.role
        def user = session.authenticated
        if (user.hasRole(roleName)) {
            body()
        }
    }

    def loginStatus = { attrs ->
        if (session.authenticated) {
            out << "Welcome ${session.authenticated.firstname} ${session.authenticated.lastname}! (${session.authenticated.username})| "
            if (attrs.showMyAccount) {
                out << "<a href=\"${createLink(controller: "myaccount")}\">My Account</a> "
            }
            def href = "${createLink(controller: "login", action: "logout")}"
            out << "| <a href='${href}'>Logout</a>"
        } else {
            def href = "${createLink(controller: "login")}"
            out << "You're not currently logged in. | <a href='${href}'>Login</a>"
        }
    }

    def loggedInUser = { attrs ->
    }

    def loggedOutUser = { attrs ->
    }

    def loginForm = { attrs ->

    }

    def forgotPassword = { attrs ->
        
    }

}